package com.atguigu.lease.web.app.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
public class StringToltemTypeConvertor implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String source) {
        //参数是前端传过来的参数，需要转换成枚举类型
        ItemType[] values = ItemType.values();
        if (values != null && values.length > 0){
            for (ItemType value : values){
                if (value.getCode().equals(Integer.valueOf(source))){
                    return value;
                }
            }
        }
        return null;
    }
}
